package com.baizhi.service.Impl;

import com.baizhi.dao.StudentDao;
import com.baizhi.dao.UserDao;
import com.baizhi.Student;
import com.baizhi.User;
import com.baizhi.service.Userservice;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserserviceImpl implements Userservice {
    @Autowired
    private UserDao us;
   @Autowired
    private StudentDao st;
    @Override
    public boolean login(String name, String pwd) {
        QueryWrapper qw=new QueryWrapper();
        qw.eq("username",name);
        qw.eq("password",pwd);
        User user = us.selectOne(qw);
        if (user==null){
            return false;
        }else{
            if (user.getUsername().equals(name)&&user.getPassword().equals(pwd)){
                return true;
            }
        }
        return false;
    }

   @Override
   public PageInfo<Student> page(int pageIndex, int pageSize) {
       Page<Object> objects = PageHelper.startPage(pageIndex, pageSize);
       List<Student> students = st.selectList(null);
       PageInfo<Student> page=new PageInfo<>(students);
       return page;
  }
}
